package com.admin.controller;


import com.admin.service.IAdminRoleService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bean.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * <p>
 *  用户角色控制层
 * </p>
 *
 * @author marisheng
 * @since 2019-11-21
 */
@RestController
@RequestMapping("/admin/role")
public class AdminRoleController {
    @Autowired
    private IAdminRoleService adminRoleService;
    @RequestMapping("/adminRole")
    public ResponseBean adminRole(@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10",name = "limit") int size,String text){
        IPage iPage =  adminRoleService.findRoleByAdmin(page,size,text);
        return new ResponseBean(0, null,iPage);
    }
    @RequestMapping("/adminRole_edit")
    public ResponseBean adminRoleEdit(){
        List<Map> maps =  adminRoleService.findAllRole();
        return new ResponseBean(0, null,maps);
    }
    @RequestMapping("/adminRole_save")
    public ResponseBean adminRoleSave(String adminId,String roleId){
        Map map = adminRoleService.adminRoleSave(adminId,roleId);
        if((int) map.get("n")>0){
            return new ResponseBean(200,"赋予角色成功",map.get("id"));
        }
        return new ResponseBean(500,"赋予角色失败",null);
    }
    @RequestMapping("/adminRole_del")
    public ResponseBean adminRoleDel(String adminRoleId){
        int n = adminRoleService.adminRoleDel(adminRoleId);
        if(n>0){
            return new ResponseBean(200,"解除角色成功",null);
        }
        return new ResponseBean(500,"解除角色失败",null);
    }
}
